package com.jp.knowledge.my.activity;

import android.content.Intent;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;

import com.google.gson.JsonObject;
import com.jiayen.util.ToasUtil;
import com.jp.knowledge.R;
import com.jp.knowledge.activity.LoginSecondActivity;
import com.jp.knowledge.broad.LocalBroadCast;
import com.jp.knowledge.http.HttpHelper;
import com.jp.knowledge.model.IModel;

/**
 * Created by 528787067@qq.com on 2017/7/18.
 */

public class BindPhoneCheckActivity extends LoginSecondActivity {

	private static final int PHONE_REBIND_CODE = 0x000005;		// 重新绑定手机

	@Override
	protected void init() {
		super.init();
		topName.setText("重新绑定手机");
		findViewById(R.id.icon_img).setVisibility(View.GONE);
		findViewById(R.id.remind_text).setVisibility(View.VISIBLE);
	}

	@Override
	protected void login() {
		JsonObject param = new JsonObject();
		param.addProperty("phone", phone);
		param.addProperty("verifyCode", smsCode.getVerifyCodeStr());
		HttpHelper.getInstance(mContext).changePhone(param, PHONE_REBIND_CODE, this);
	}

	@Override
	public void onNext(IModel data, int requestType) {
		if(requestType == PHONE_REBIND_CODE){
			if(data.getErrcode() != 0){
				ToasUtil.toast(mContext, data.getMessage());
				onError(requestType);
			} else{
				LocalBroadcastManager.getInstance(mContext)
						.sendBroadcast(new Intent(LocalBroadCast.PHONE_REBIND_CODE)
								.putExtra("phone", phone));
				application.closeLoginActivity();
			}
			return;
		}
		super.onNext(data, requestType);
	}
}
